package com.sise.producer8002.service.Impl;

import com.sise.producer8002.service.MessageProvider;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.MessageBuilder;

import javax.annotation.Resource;

/**
 * @author:ljf
 * @date: 2020/6/8
 * @description:
 **/
@EnableBinding(Source.class) //定义消息的推送管道
public class MessageProviderImpl implements MessageProvider {

    @Resource
    private MessageChannel output;  //消息发送管道

    @Override
    public String sendMessage(String msg) {

        //发送
        //build方法会构建一个Message类
        output.send(MessageBuilder.withPayload(msg).build());

        System.out.println("生产者  sendMessage:" + msg);

        return null;
    }
}
